
import { Component, OnInit,ViewChild } from '@angular/core';
import 'rxjs/add/operator/map';
import { Observable } from 'rxjs/Rx';
import { CommService } from '../../comm/comm.service';
import { ReportUrls } from '../../comm/report.urls.conf';
import { TIP } from '../../model/report/tip';
import { SubArea } from '../../model/report/sub-area';
import { QueryModel } from '../../model/report/query-model';
import { ChartOptionCreater } from '../../model/comm/chart-option-creater';
import 'rxjs/add/operator/toPromise';
declare const $: any;
import { DxDropDownBoxComponent } from 'devextreme-angular';
import * as Enumerable from 'linq';
import { TVResource } from 'app/ptpmc/model/comm/tv-resource';
@Component({
    selector: 'app-report-startup',
    templateUrl: './startup.component.html',
    styleUrls: ['./startup.component.scss']
})

export class StartUpComponent implements OnInit {
    title = '设备开动率';
    public startupList: any[];
    public topCount: number = 5;
    //界面显示数据定义
    public tipGridList: TIP[];
    public topGridList1: any[];
    public topGridList2: any[];
    public topGridList3: any[];
    public topGridList4: any[];
    public topGridList5: any[];
    public tipChartOption0: any;
    public tipChartOption1: any;
    public tipChartOption2: any;
    public tipChartOption3: any;
    public tipChartOption4: any;
    public tipChartOption5: any;
    public tipChartOption6: any;
    public tipChartOption7: any;
    public tipChartOption8: any;
    public tipChartOption9: any;
    public tipChartOption10: any;
    public tipChartOption11: any;

    
    constructor(private commServices: CommService) {
    }
    //组件初始化
    ngOnInit() {
        this.commServices.initDatePicker($('#DateTimeRange'), 'YYYY-MM-DD');
        this.shiftItems = this.commServices.shifts;
        this.shiftSelected = this.shiftItems[0];
        this.subAreaItems = this.commServices.getSubAreas();
        this.subAreaSelected = [];
        this.subAreaSelected.forEach(e => {
            const arr = this.commServices.getTVResourceBySubArea(e.subArea);
            arr.forEach(a => { this.equipemntItems.push(a); });
        });
        debugger
        //this.equipemntItems = this.commServices.getSlowestResourceBySubArea(this.subAreaItems[0].subArea);
        //this.equipmentSelected = this.equipemntItems[0];
        //this.showTIPTopGrid();
    }

    showloading = true;

    /*生产线 - 班次*/
    public subAreaItems: SubArea[];
    public shiftItems: any[];
    public equipemntItems: TVResource[] = [];
    public subAreaSelected: any[];
    public subAareSelected: any;
    public shiftSelected: any;
    public equipmentSelected: TVResource;
    public totTIPData = new TIP();
    @ViewChild('dddb') dddb: DxDropDownBoxComponent;
    @ViewChild('ddda') ddda: DxDropDownBoxComponent;

    /**
     * 获取表格数据
     */
    onSubAreaSelectedChange(subArea: any): void {
        this.equipemntItems = this.commServices.getSlowestResourceBySubArea(subArea.value.subArea);
        this.equipmentSelected = this.equipemntItems[0];
        debugger
    }
    getReportData(): void {
        const queryModel: QueryModel = new QueryModel();
        queryModel.dateTimeRange = this.getTime('DateTimeRange');
        queryModel.querySubAreaIds = this.subAreaSelected.map(e => e.subArea);;
        //queryModel.shift = this.shiftSelected.shiftId;
        //queryModel.queryResourceIds = [this.equipmentSelected.resource];
        debugger
        //获取设备故障信息显示
        this.commServices
            .getList(queryModel, ReportUrls.StartUpUrl)
            .subscribe(model => {
                if (model.resultCode === 200) {
                    debugger
                    this.startupList = model.data;
                    const time =  this.getTime('DateTimeRange') ;
                    // this.tipList = this.tipList.filter(item => item.resource == queryModel.queryResourceIds[0] || item.unloadOP == 1);
                    // this.tipList.forEach(item => {
                    //     item.perUptimeReate = item.perUptimeReate > 1 ? 1 : item.perUptimeReate;
                    //})

                    // this.getTIPGroupList();
                    // this.showTIPChart();

                    // this.tipList.forEach(item => {
                    //     item.perUptimeReate = (item.perUptimeReate * 100).toFixed(2) + '%';
                    //     item.perDowntime = (item.perDowntime * 100).toFixed(2) + '%';
                    //     item.perToolchange = (item.perToolchange * 100).toFixed(2) + '%';
                    //     item.perBlocked = (item.perBlocked * 100).toFixed(2) + '%';
                    //     item.perStarved = (item.perStarved * 100).toFixed(2) + '%';
                    //})

                } else {
                    console.log(model.resultCode + ',' + model.resultMessage);
                }
            });
    }
    // private getTIPGroupList() {
    //     const slowestList: TIP[] = Enumerable.from(this.tipList).where(u => u.slowestOP == 1).toArray();
    //     const unloadOPList: TIP[] = Enumerable.from(this.tipList).where(u => u.unloadOP == 1).toArray();
    //     slowestList.forEach(u => {
    //         const offlines: TIP[] = Enumerable.from(unloadOPList).where(e => e.productDate == u.productDate && e.shift == u.shift).toArray();
    //         //瓶颈jph即为该设备的实际jph；
    //         u.bbottleneckJPH = u.ajph;
    //         //下线实际jph为下线各个设备的jph和*该瓶颈工位的权重
    //         if (offlines != null && offlines.length > 0) {
    //             u.offLineJPH = Number.parseFloat((Enumerable.from(offlines).sum(u => u.ajph) * u.weight).toFixed(2));
    //             u.offLineCount = Number.parseFloat((Enumerable.from(offlines).sum(u => u.actual) * u.weight).toFixed(2));
    //         }
    //         u.mtbf = Number.parseFloat(u.mtbf.toFixed(2));
    //         u.mttr = Number.parseFloat(u.mttr.toFixed(2));
    //         u.mcbf = Number.parseFloat(u.mcbf.toFixed(2));
    //     });
    //     this.tipGridList = slowestList;
    //     //取得汇总数据
    //     this.totTIPData.ratedCT = Number.parseFloat(Enumerable.from(this.tipGridList).average(u => u.ratedCT).toFixed(2));
    //     this.totTIPData.actualCT = Number.parseFloat(Enumerable.from(this.tipGridList).average(u => u.actualCT).toFixed(2));
    //     this.totTIPData.actual = Number.parseFloat(Enumerable.from(this.tipGridList).sum(u => u.actual).toFixed(2));
    //     this.totTIPData.offLineCount = Number.parseFloat(Enumerable.from(this.tipGridList).sum(u => u.offLineCount).toFixed(2));
    //     this.totTIPData.totCT = Number.parseFloat(Enumerable.from(this.tipGridList).sum(u => u.totCT).toFixed(2));
    //     this.totTIPData.downCount = Number.parseFloat(Enumerable.from(this.tipGridList).sum(u => u.downCount).toFixed(2));
    //     this.totTIPData.downTime = Number.parseFloat(Enumerable.from(this.tipGridList).sum(u => u.downTime).toFixed(2));
    //     this.totTIPData.numTCT = Number.parseFloat(Enumerable.from(this.tipGridList).sum(u => u.numTCT).toFixed(2));
    //     this.totTIPData.totTCT = Number.parseFloat(Enumerable.from(this.tipGridList).sum(u => u.totTCT).toFixed(2));
    //     this.totTIPData.numBT = Number.parseFloat(Enumerable.from(this.tipGridList).sum(u => u.numBT).toFixed(2));
    //     this.totTIPData.totBT = Number.parseFloat(Enumerable.from(this.tipGridList).sum(u => u.totBT).toFixed(2));
    //     this.totTIPData.numST = Number.parseFloat(Enumerable.from(this.tipGridList).sum(u => u.numST).toFixed(2));
    //     this.totTIPData.totST = Number.parseFloat(Enumerable.from(this.tipGridList).sum(u => u.totST).toFixed(2));
    //     this.totTIPData.totWorkTime = Number.parseFloat(Enumerable.from(this.tipGridList).sum(u => u.totWorkTime).toFixed(2));
    //     this.totTIPData.grossJPH = Number.parseFloat(Enumerable.from(this.tipGridList).average(u => u.grossJPH).toFixed(2));
    //     this.totTIPData.perUptimeReate = Number.parseFloat(Enumerable.from(this.tipGridList).average(u => u.perUptimeReate).toFixed(4));
    //     this.totTIPData.perDowntime = Number.parseFloat(Enumerable.from(this.tipGridList).average(u => u.perDowntime).toFixed(2));
    //     this.totTIPData.perToolchange = Number.parseFloat(Enumerable.from(this.tipGridList).average(u => u.perToolchange).toFixed(2));
    //     this.totTIPData.perBlocked = Number.parseFloat(Enumerable.from(this.tipGridList).average(u => u.perBlocked).toFixed(2));
    //     this.totTIPData.perStarved = Number.parseFloat(Enumerable.from(this.tipGridList).average(u => u.perStarved).toFixed(2));
    //     this.totTIPData.mtbf = Number.parseFloat(Enumerable.from(this.tipGridList).average(u => u.mtbf).toFixed(2));
    //     this.totTIPData.mcbf = Number.parseFloat(Enumerable.from(this.tipGridList).average(u => u.mcbf).toFixed(2));
    //     this.totTIPData.mttr = Number.parseFloat(Enumerable.from(this.tipGridList).average(u => u.mttr).toFixed(2));
    //     this.totTIPData.perSAA = Number.parseFloat(Enumerable.from(this.tipGridList).average(u => u.perSAA).toFixed(2));
    //     this.totTIPData.saajph = Number.parseFloat(Enumerable.from(this.tipGridList).average(u => u.saajph).toFixed(2));
    //     this.totTIPData.bbottleneckJPH = Number.parseFloat(Enumerable.from(this.tipGridList).average(u => u.bbottleneckJPH).toFixed(2));
    //     this.totTIPData.offLineJPH = Number.parseFloat(Enumerable.from(this.tipGridList).average(u => u.offLineJPH).toFixed(2));
    // }


    /**
     * 获取TimeRange的值
     * @param id id
    */
    getTime(id: any): String {
        const timerange: String = $('#' + id).val();
        // const timeArray: Array<String> = timerange.split(' - ');
        return timerange;
    }
    // clearEquipmentSelected() {
    //     this.equipmentSelected = [];
    // }
    // equipmentSelectedOk() {
    //     this.dddb.instance.close();
    // }
    clearSubAreaSelected() {
        this.subAreaSelected = [];
    }
    subAreaSelectedOk() {
        this.ddda.instance.close();
    }
    // private showTIPTopGrid(): void {
    //     const topList: Array<{ index: string, problem: string, frequency: String, time: String, measures: String }> = [
    //         { index: "1", problem: "", frequency: "", time: "", measures: "" },
    //         { index: "2", problem: "", frequency: "", time: "", measures: "" },
    //         { index: "3", problem: "", frequency: "", time: "", measures: "" },
    //         { index: "4", problem: "", frequency: "", time: "", measures: "" },
    //         { index: "5", problem: "", frequency: "", time: "", measures: "" },
    //     ];
    //     this.topGridList1 = topList;
    //     this.topGridList2 = topList;
    //     this.topGridList3 = topList;
    //     this.topGridList4 = topList;
    //     this.topGridList5 = topList;
    // }
    /**ECharts图表相关*/
    chartsMap = new Map<any, any>();
    onChartInit(index: any, echartsIntance: any): void {
        this.chartsMap.set(index, echartsIntance);
        Observable.fromEvent(window, 'resize')
            .debounceTime(100) // 以免频繁处理
            .subscribe(() => this.chartsMap.forEach((v) => v.resize()));
    }

    selectedIndexChange(tabIndex: any) {
        this.chartsMap.get(tabIndex).resize();
    }
    // private showTIPChart(): void {
    //     const xData = new Array();
    //     const tipSAAJPH = new Array();
    //     const tipGrossJPH = new Array();
    //     const tipBbottleneckJPH = new Array();
    //     const tipOffLineJPH = new Array();
    //     const tipRatedCT = new Array();
    //     const tipActualCT = new Array();
    //     const tipPerSAA = new Array();
    //     const tipMTTR = new Array();
    //     const tipMCBF = new Array();
    //     const tipPerDowntime = new Array();
    //     const tipPerStarved = new Array();
    //     const tipPerBlocked = new Array();
    //     const tipPerToolchange = new Array();
    //     const tipPerUptimeReate = new Array();
    //     let tipChartSeries1 = new Array();
    //     let tipChartSeries2 = new Array();
    //     let tipChartSeries3 = new Array();
    //     let tipChartSeries4 = new Array();
    //     let tipChartSeries5 = new Array();
    //     let tipChartSeries6 = new Array();
    //     let tipChartSeries7 = new Array();
    //     let tipChartSeries8 = new Array();
    //     let tipChartSeries9 = new Array();
    //     let tipChartSeries10 = new Array();
    //     let pieData = {
    //         timeLineData: new Array(), name: '',
    //         legendData: ['Uptime %', 'Downtime %', 'Toolchange %', 'Blocked %', 'Starved %'], totalData: new Array(), optionsData: new Array()
    //     };

    //     this.tipGridList.forEach(u => {
    //         xData.push(u.productDate + '-' + u.shift);
    //         pieData.timeLineData.push(u.productDate + '-' + u.shift);
    //         pieData.optionsData.push({
    //             series: [{
    //                 data: [(u.perUptimeReate * 100).toFixed(2)],
    //                 itemStyle: {
    //                     normal: { color: '#00FF00' },
    //                 },
    //             },
    //             {
    //                 data: [u.perDowntime.toFixed(2)],
    //                 itemStyle: {
    //                     normal: { color: '#FF0000' },
    //                 },
    //             },
    //             {
    //                 data: [u.perToolchange.toFixed(2)],
    //                 itemStyle: {
    //                     normal: { color: '#FFFF00' },
    //                 },
    //             },
    //             {
    //                 data: [u.perBlocked.toFixed(2)],
    //                 itemStyle: {
    //                     normal: { color: '#E2E2E2' },
    //                 },
    //             },
    //             {
    //                 data: [u.perStarved.toFixed(2)],
    //                 itemStyle: {
    //                     normal: { color: '#BFBFBF' },
    //                 },
    //             }
    //             ]
    //         });
    //         // barDataJph.SeriesData[0].data.push(itemjson.Data[i].SAA_JPH.toFixed(2));
    //         // barDataJph.SeriesData[1].data.push(itemjson.Data[i].BbottleneckJPH.toFixed(2));
    //         // barDataJph.SeriesData[2].data.push(itemjson.Data[i].GrossJPH.toFixed(2));
    //         // barDataJph.SeriesData[3].data.push(itemjson.Data[i].OffLineJPH.toFixed(2));
    //         // barDataCycletime.SeriesData[0].data.push(itemjson.Data[i].RatedCT.toFixed(2));
    //         // barDataCycletime.SeriesData[1].data.push(itemjson.Data[i].ActualCT.toFixed(2));
    //         // barDataSaa.SeriesData[0].data.push(itemjson.Data[i].Per_SAA.toFixed(2));
    //         // barDataMttr.SeriesData[0].data.push(itemjson.Data[i].MTTR.toFixed(2));
    //         // barDataMcbf.SeriesData[0].data.push(itemjson.Data[i].MCBF.toFixed(2));
    //         // barDataDowntime.SeriesData[0].data.push(itemjson.Data[i].Per_Downtime.toFixed(2));
    //         // barDataStarved.SeriesData[0].data.push(itemjson.Data[i].Per_Starved.toFixed(2));
    //         // barDataBlocked.SeriesData[0].data.push(itemjson.Data[i].Per_Blocked.toFixed(2));
    //         // barDataToolchange.SeriesData[0].data.push(itemjson.Data[i].Per_Toolchange.toFixed(2));
    //         // barDataUptime.SeriesData[0].data.push(itemjson.Data[i].Per_UptimeReate.toFixed(2));
    //         //根据数据班次存放数据

    //         tipSAAJPH.push(u.saajph);
    //         tipBbottleneckJPH.push(u.bbottleneckJPH);
    //         tipGrossJPH.push(u.grossJPH)
    //         tipOffLineJPH.push(u.offLineJPH);
    //         tipRatedCT.push(u.ratedCT);
    //         tipActualCT.push(u.actualCT);
    //         tipPerSAA.push(u.perSAA * 100);
    //         tipMTTR.push(u.mttr);
    //         tipMCBF.push(u.mcbf);
    //         tipPerDowntime.push(u.perDowntime * 100);
    //         tipPerStarved.push(u.perStarved * 100);
    //         tipPerBlocked.push(u.perBlocked * 100);
    //         tipPerToolchange.push(u.perToolchange * 100);
    //         tipPerUptimeReate.push(u.perUptimeReate * 100);

    //     });
    //     pieData.totalData.push({
    //         value: this.totTIPData.perUptimeReate.toFixed(2), name: 'Uptime %',
    //         itemStyle: {
    //             normal: { color: '#00FF00' },
    //         },
    //     });
    //     pieData.totalData.push({
    //         value: this.totTIPData.perDowntime.toFixed(2), name: 'Downtime %',
    //         itemStyle: {
    //             normal: { color: '#FF0000' },
    //         },
    //     });
    //     pieData.totalData.push({
    //         value: this.totTIPData.perToolchange.toFixed(2), name: 'Toolchange %',
    //         itemStyle: {
    //             normal: { color: '#FFFF00' },
    //         },
    //     });
    //     pieData.totalData.push({
    //         value: this.totTIPData.perBlocked.toFixed(2), name: 'Blocked %',
    //         itemStyle: {
    //             normal: { color: '#E2E2E2' },
    //         },
    //     });
    //     pieData.totalData.push({
    //         value: this.totTIPData.perStarved.toFixed(2), name: 'Starved %',
    //         itemStyle: {
    //             normal: { color: '#BFBFBF' },
    //         },
    //     });

    //     tipChartSeries1.push(
    //         {
    //             name: '% Uptime',
    //             type: 'line',
    //             data: tipPerUptimeReate
    //         }
    //     )
    //     tipChartSeries2.push(
    //         {
    //             name: '% Tool Changed',
    //             type: 'line',
    //             data: tipPerToolchange
    //         }
    //     )
    //     tipChartSeries3.push(
    //         {
    //             name: '% Blocked',
    //             type: 'line',
    //             data: tipPerBlocked
    //         }
    //     )
    //     tipChartSeries4.push(
    //         {
    //             name: '% Starved',
    //             type: 'line',
    //             data: tipPerStarved
    //         }
    //     )
    //     tipChartSeries5.push(
    //         {
    //             name: '% DownTime',
    //             type: 'line',
    //             data: tipPerDowntime
    //         }
    //     )
    //     tipChartSeries6.push(
    //         {
    //             name: 'MCBF',
    //             type: 'line',
    //             data: tipMCBF
    //         }
    //     )
    //     tipChartSeries7.push(
    //         {
    //             name: 'MTTR',
    //             type: 'line',
    //             data: tipMTTR
    //         }
    //     )
    //     tipChartSeries8.push(
    //         {
    //             name: '% SAA',
    //             type: 'line',
    //             data: tipPerSAA
    //         }
    //     )
    //     tipChartSeries9.push(
    //         {
    //             name: '设定节拍',
    //             type: 'line',
    //             data: tipRatedCT
    //         }
    //     )
    //     tipChartSeries9.push(
    //         {
    //             name: '实际节拍',
    //             type: 'line',
    //             data: tipActualCT
    //         }
    //     )
    //     tipChartSeries10.push(
    //         {
    //             name: 'SAA JPH',
    //             type: 'line',
    //             data: tipSAAJPH,
    //             itemStyle: {
    //                 normal: { color: 'red' },
    //             },
    //         }
    //     )
    //     tipChartSeries10.push(
    //         {
    //             name: '瓶颈 JPH',
    //             type: 'line',
    //             data: tipBbottleneckJPH,
    //             itemStyle: {
    //                 normal: { color: 'blue' },
    //             },
    //         }
    //     )
    //     tipChartSeries10.push(
    //         {
    //             name: 'Gross JPH',
    //             type: 'line',
    //             data: tipGrossJPH,
    //             itemStyle: {
    //                 normal: { color: 'green' },
    //             },
    //         }
    //     )
    //     tipChartSeries10.push(
    //         {
    //             name: '下线 JPH',
    //             type: 'line',
    //             data: tipOffLineJPH,
    //             itemStyle: {
    //                 normal: { color: 'black' },
    //             },
    //         }
    //     )
    //     let legend1 = ['% Uptime'];
    //     let legend2 = ['% Tool Changed'];
    //     let legend3 = ['% Blocked'];
    //     let legend4 = ['% Starved'];
    //     let legend5 = ['% DownTime'];
    //     let legend6 = ['MCBF'];
    //     let legend7 = ['MTTR'];
    //     let legend8 = ['% SAA'];
    //     let legend9 = ['设定节拍', '实际节拍'];
    //     let legend10 = ['SAA JPH', '瓶颈 JPH', 'Gross JPH', '下线 JPH'];
    //     this.tipChartOption0 = ChartOptionCreater.createPieTimeChartsSummary(pieData);
    //     this.tipChartOption1 = ChartOptionCreater.createPieTimeCharts(pieData);
    //     this.tipChartOption2 = ChartOptionCreater.createChartsOption('', '', '%', '', legend1, xData, tipChartSeries1, null);//% Uptime
    //     this.tipChartOption3 = ChartOptionCreater.createChartsOption('', '', '%', '', legend2, xData, tipChartSeries2, null);//% Tool Changed
    //     this.tipChartOption4 = ChartOptionCreater.createChartsOption('', '', '%', '', legend3, xData, tipChartSeries3, null);//% Blocked
    //     this.tipChartOption5 = ChartOptionCreater.createChartsOption('', '', '%', '', legend4, xData, tipChartSeries4, null);//% Starved
    //     this.tipChartOption6 = ChartOptionCreater.createChartsOption('', '', '%', '', legend5, xData, tipChartSeries5, null);//% DownTime
    //     this.tipChartOption7 = ChartOptionCreater.createChartsOption('', '', '', '', legend6, xData, tipChartSeries6, null);//MCBF
    //     this.tipChartOption8 = ChartOptionCreater.createChartsOption('', '', '', '', legend7, xData, tipChartSeries7, null);//MTTR
    //     this.tipChartOption9 = ChartOptionCreater.createChartsOption('', '', '%', '', legend8, xData, tipChartSeries8, null);//% SAA
    //     this.tipChartOption10 = ChartOptionCreater.createChartsOption('', '', '秒', '', legend9, xData, tipChartSeries9, null);//Cycle Time
    //     this.tipChartOption11 = ChartOptionCreater.createChartsOption('', '', 'JPH', '', legend10, xData, tipChartSeries10, null);//BN Throughput(JPH)
    //     //this.showloading = false;

    //     // 数据展示
    //     // if(itemjson.TotalData.TotWorkTime > 0)
    //     // {
    //     //     $("#downtime").html((itemjson.TotalData.Per_Downtime).toFixed(2) + "<small>%</small>");
    //     //     $("#uptime").html((itemjson.TotalData.Per_UptimeReate).toFixed(2) + " <small>%</small>");
    //     //     $("#toolchange").html((itemjson.TotalData.Per_Toolchange).toFixed(2) + " <small>%</small>");
    //     //     $("#blocked").html((itemjson.TotalData.Per_Blocked).toFixed(2) + " <small>%</small>");
    //     //     $("#starved").html((itemjson.TotalData.Per_Starved).toFixed(2) + " <small>%</small>");
    //     //     $("#mcbf").html(itemjson.TotalData.MCBF.toFixed(2));
    //     //     $("#mttr").html(itemjson.TotalData.MTTR.toFixed(2));
    //     //     $("#ctTime").html(itemjson.TotalData.ActualCT.toFixed(2) + " <small>Sec</small>");
    //     //     $("#grossJPH").html(itemjson.TotalData.GrossJPH.toFixed(2) + " <small>JPH</small>");
    //     //     $("#saaJPH").html(itemjson.TotalData.SAA_JPH.toFixed(2) + " <small>JPH</small>");
    //     //     $("#bJPH").html(itemjson.TotalData.BbottleneckJPH.toFixed(2) + " <small>JPH</small>");
    //     //     $("#offlineJPH").html(itemjson.TotalData.OffLineJPH.toFixed(2) + " <small>JPH</small>");

    //     // }
    // }

    protected exportData() {
        const files = new Array<any>();
        const queryModelArray = new Array<any>();

        const tables = new Array<any>();

        const row1 = new Array();
        this.topGridList1.forEach((e: { index: string, problem: string, frequency: String, time: String, measures: String }) => {
            const co = new Array();
            co.push(e.index);
            co.push(e.problem);
            co.push(e.frequency);
            co.push(e.time);
            co.push(e.measures);
            row1.push(co);
        });
        const table1 = {
            tableName: 'TOP问题',
            titles: ['NO.', 'Downtime问题汇总', '频次', '时间', '长期措施'],
            rows: row1
        };

        const row2 = new Array();
        this.topGridList2.forEach((e: { index: string, problem: string, frequency: String, time: String, measures: String }) => {
            const co = new Array();
            co.push(e.index);
            co.push(e.problem);
            co.push(e.frequency);
            co.push(e.time);
            co.push(e.measures);
            row2.push(co);
        });
        const table2 = {
            tableName: '',
            titles: ['NO.', 'CyclerTime问题汇总', '频次', '时间', '长期措施'],
            rows: row2
        };

        const row3 = new Array();
        this.topGridList3.forEach((e: { index: string, problem: string, frequency: String, time: String, measures: String }) => {
            const co = new Array();
            co.push(e.index);
            co.push(e.problem);
            co.push(e.frequency);
            co.push(e.time);
            co.push(e.measures);
            row3.push(co);
        });
        const table3 = {
            tableName: '',
            titles: ['NO.', 'Toolchange问题汇总', '频次', '时间', '长期措施'],
            rows: row3
        };

        const row4 = new Array();
        this.topGridList4.forEach((e: { index: string, problem: string, frequency: String, time: String, measures: String }) => {
            const co = new Array();
            co.push(e.index);
            co.push(e.problem);
            co.push(e.frequency);
            co.push(e.time);
            co.push(e.measures);
            row4.push(co);
        });
        const table4 = {
            tableName: '',
            titles: ['NO.', 'Starved问题汇总', '频次', '时间', '长期措施'],
            rows: row4
        };

        const row5 = new Array();
        this.topGridList5.forEach((e: { index: string, problem: string, frequency: String, time: String, measures: String }) => {
            const co = new Array();
            co.push(e.index);
            co.push(e.problem);
            co.push(e.frequency);
            co.push(e.time);
            co.push(e.measures);
            row5.push(co);
        });
        const table5 = {
            tableName: '',
            titles: ['NO.', 'Blocked问题汇总', '频次', '时间', '长期措施'],
            rows: row5
        };

        tables.push(table1);
        tables.push(table2);
        tables.push(table3);
        tables.push(table4);
        tables.push(table5);

        queryModelArray.push('时间:' + this.getTime('DateTimeRange'));
        queryModelArray.push('区域:' + this.subAareSelected.subArea);
        queryModelArray.push('设备:' + this.equipmentSelected.equipment);
        queryModelArray.push('班次:' + (this.shiftSelected.shiftId === '-1' ? '全部' : this.shiftSelected.shiftId === '1' ? '早班' : '中班'));
        this.chartsMap.forEach((v, k) => {
            if (k !== 0) {
                const picBase64Info = v.getDataURL();
                const newPahge =  k == '%Tool changed' || k == '%Starved' ||  k == 'MCBF'||  k == '%SAA'||  k ==  'BN Throughput(JPH)';
                files.push({ chartsTitle: k, chartsEncodeStr: picBase64Info, nextNewPage: newPahge ? 2 : 0 });
            }
        });

        const upload = {
            reportTitle: this.title,
            charts: files,
            queryModel: queryModelArray,
            tables: tables
        };

        this.commServices.exportPdf(upload);
    }

    onExporting(e) {
        e.fileName = e.fileName + new Date().toISOString().replace(/[\-\:\.]/g, '').split('T')[0];
    }
}
